java文件读写 |
您所在的位置:网站首页 › java 文件写入 › java文件读写 |
package velcro.util;
import java.io.File; import java.io.FileWriter; import java.io.IOException;
/**
* 对文本文件进行读写操作
*/ public class WriteAndReadText {
/**
* 文本文件所在的目录
*/
private String textPath;
/**
* 读取文本内容
* @param textname 文本名称
* @return
*/
public String readText(String textname){
File file=new File(textPath+File.separator+textname);
try {
BufferedReader br = new BufferedReader(new java.io.FileReader(file));
StringBuffer sb = new StringBuffer();
String line = br.readLine();
while (line != null) {
sb.append(line);
line = br.readLine();
}
br.close();
return sb.toString();
} catch (IOException e) {
LogInfo.error(this.getClass().getName(),e.getLocalizedMessage(),e);
e.printStackTrace();
return null;
}
}
}
/**
* 将内容写到文本中
* @param textname
文本名称
* @param date 写入的内容
* @return
*/ |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |